<?php
	// Check crossing acess
    if (!defined('RIGHT_ACCESS') || !defined('ROOT_FOLDER'))
    {
        header('Content-Type: text/xml; charset=utf-8');
        echo '<?xml version="1.0"?>';
        echo '<atomtask>';
        echo '<request>error.request.invalid</request>';
        echo '</atomtask>';
        return;
    }   

	// Authorize
	include_once(ROOT_FOLDER.'api/auth.php');
    include_once(ROOT_FOLDER.'includes/project_func.php');
    include_once(ROOT_FOLDER.'db/connect_db.php');

    // Check authorization
	if (!isset($valid_auth) || !$valid_auth)
		return;

	// Get load all project that have 
    $result = Project::get_user_projects($auth->user_id);
    if (!$result)
    {
    	XML::write_element('result', 'error.request.unknown');
    	return;
    }
    if (mysql_num_rows($result) == 0)
    {
        XML::write_element('result', 'success.project.get_user_projects.nothing');
    	return;
    }
    XML::write_element('result', 'success.project.get_user_projects.list');
    XML::start_element('projects_list');
    XML::write_element('list_amount', mysql_num_rows($result));
    while($item = mysql_fetch_assoc($result))
    {
        XMl::start_element('project');
        /*
        XMl::write_element('project_id', htmlentities($item['project_id'],ENT_COMPAT,'utf-8'));
        XMl::write_element('project_name', htmlentities($item['project_name'],ENT_COMPAT,'utf-8'));
        XMl::write_element('project_description', htmlentities($item['project_description'],ENT_COMPAT,'utf-8'));
        XMl::write_element('creator', htmlentities($item['creator'],ENT_COMPAT,'utf-8'));
        */
        XMl::write_element('project_id',$item['project_id']);
        XMl::write_element('project_name', $item['project_name']);
        XMl::write_element('project_description', $item['project_description']);
        XMl::write_element('creator',$item['creator']);

        $join_type = 'member';
    	if ($item['creator'] == $auth->username)
    		$join_type = 'creator';
    	else
    		if ($item['wait'] == '1')
    			$join_type = 'inviting';
        XMl::write_element('join_type', $join_type);

        XMl::write_element('join_date', $item['join_date']);
        XML::end_element();
    }
    XML::end_element();
?>